package cn.bigcontainer.alt.meta.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import cn.bigcontainer.alt.meta.dto.MySqlColumn;

/**
 * @author cailei
 * @date 2016年6月2日
 */
@Mapper
public interface DbMetaDao {

	/**
	 * 
	 * @return
	 */
	@Select("select LOWER(TABLE_NAME) as tablename,TABLE_COMMENT as comment, LOWER(TABLE_SCHEMA) as schemaname from information_schema.TABLES where TABLE_SCHEMA = database()")
	public List<Map<String, Object>> queryAllTables();

	@Select("select TABLE_COMMENT from information_schema.TABLES where TABLE_NAME = #{table} and TABLE_SCHEMA = database()")
	public String queryTableComment(String table);

	/**
	 * 
	 * @param table
	 * @return
	 */
	@SelectProvider(type = DbMetaDaoProvider.class, method = "getAllColumnsSQL")
	@Results({ @Result(column = "Field", property = "field"), @Result(column = "Type", property = "type"),
			@Result(column = "Comment", property = "comment"),
			@Result(column = "Null", property = "allowsNull"), @Result(column = "Key", property = "key"),
			@Result(column = "Default", property = "defaultValue"), @Result(column = "Extra", property = "extra") })
	public List<MySqlColumn> queryColumns(String table);
}
